<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/28
 * Time: 15:51
 */

namespace Home\Controller;


class ConfigController extends HomeController
{
    public function index(){
        $this->assign('default_city', C('DEFAULT_CITY'));
        $this->assign('app_report_interval', C('APP_REPORT_INTERVAL'));
        $this->assign('max_send_file', C('MAX_SEND_FILE'));
        $this->assign('map_refresh_interval', C('MAP_REFRESH_INTERVAL'));
        $this->meta_title = '配置管理';
        $this->display();
    }

    public function updateConfig(){
        $data['DEFAULT_CITY'] = C('DEFAULT_CITY');
        $data['APP_REPORT_INTERVAL'] = C('APP_REPORT_INTERVAL');
        $data['MAX_SEND_FILE'] = C('MAX_SEND_FILE');
        $data['MAP_REFRESH_INTERVAL'] = C('MAP_REFRESH_INTERVAL');
        if (isset($_POST['map_refresh_interval']))$data['MAP_REFRESH_INTERVAL'] = $_POST['map_refresh_interval'];
        if (isset($_POST['default_city']))$data['DEFAULT_CITY'] = $_POST['default_city'];
        if (isset($_POST['app_report_interval']))$data['APP_REPORT_INTERVAL'] = $_POST['app_report_interval'];
        if (isset($_POST['max_send_file']))$data['MAX_SEND_FILE'] = $_POST['max_send_file'];
        $output = var_export($data, true);
//        F('setting', $data, CONF_PATH);
        $output = "<?php \n return " . $output . ';';
        $file_path = CONF_PATH . 'setting.php';
        file_put_contents($file_path, $output);
//        $cacheddir = RUNTIME_PATH . '/Cache';

        $this->sucessJson();
    }

}